#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
using ll = long long;
const int mod = 998244353;
int n;
ll qmi(ll a, ll k)
{
    ll res = 1;
    while (k)
    {
        if (k & 1) res = res * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return res;
}
int main()
{
    cin >> n;
    ll res = 0;
    while (n--)
    {
        ll x, y;
        cin >> x >> y;
        res = (res + 1ll) * y % mod * qmi(y - x, mod - 2) % mod;
    }
    cout << res << endl;
}